//
//  DoorViewController.m
//  WheatPlan
//
//  Created by giantumbrella on 15/5/21.
//  Copyright (c) 2015年 IOSTeam. All rights reserved.
//

#import "DoorViewController.h"
#import "CommonMacro.h"
#import "UnderstandViewController.h"
#import "IntroductionViewController.h"
#import "TeacherViewController.h"
#import "AppointmentViewController.h"
#import "IndividualViewController.h"
#import "CourseViewController.h"
#import "UIImageView+WebCache.h"
@interface DoorViewController (){
    
    NSData *data1;
    NSData *data2;
    NSData *data3;
    NSData *data4;

    NSArray *_provinceArray;
    NSArray *arra;

    
}

@end

@implementation DoorViewController


-(void)viewDidAppear:(BOOL)animated{
    
    self.tabBarController.tabBar.selectedImageTintColor = [GetFileModel colorWithHexString:@"#ef5858" alpha:1];

    
    if ([BabyManager shareInstance].babyId == nil) {
        
        [self.tabBarController setSelectedIndex:0];
        [self ShowProgressHUDwithMessage:@"请先添加宝宝"];
        
    }
    


//    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
//    NSString *ID = [user objectForKey:@"ID"];
    ////NSLog(@"%@uououououououou",[BabyManager shareInstance].babyId);
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString *ID = [user objectForKey:@"babyIDD"];
    ////NSLog(@"%@我是谁",ID);
    
}
- (void)ShowProgressHUDwithMessage:(NSString *)msg
{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.labelText = msg;
    hud.dimBackground = NO;
    hud.removeFromSuperViewOnHide = YES;
    [hud hide:YES afterDelay:1];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    
    
    //设置导航栏头文字
    self.navigationItem.title = @"上门早教";
    //设置导航栏背景颜色
    [self.navigationController.navigationBar setBarTintColor:[GetFileModel colorWithHexString:@"#ef5858" alpha:1]];
    //设置导航栏字体颜色
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]];
    
    [self initSubViews];
  
    

    // Do any additional setup after loading the view from its nib.
}

-(void)initSubViews{
    
    
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];

    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString *ID = [user objectForKey:@"ID"];
    ////NSLog(@"%@看看我是谁",ID);

    
    NSDictionary *param = @{@"userId": ID,@"ealyType":@"1"};
    
    [UserDAL getPreschoolEducationInfoParams:param withBlock:^(NSArray *data, NSError *error) {
        
        [MBProgressHUD hideHUDForView:self.view animated:YES];

        if (data) {
            
            if (data.count!=0) {
//            ////NSLog(@"%@",data);
            
            _provinceArray = data;
            
            
         
            NSURL *url=[NSURL URLWithString:_provinceArray[0][@"ImageUrl"]];
            data1=[NSData dataWithContentsOfURL:url];
                
            NSURL *url1=[NSURL URLWithString:_provinceArray[1][@"ImageUrl"]];
            data2=[NSData dataWithContentsOfURL:url1];
            
            NSURL *url2=[NSURL URLWithString:_provinceArray[2][@"ImageUrl"]];
            data3=[NSData dataWithContentsOfURL:url2];
            
            NSURL *url3=[NSURL URLWithString:_provinceArray[3][@"ImageUrl"]];
            data4=[NSData dataWithContentsOfURL:url3];
            
            

       
            _understandBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            _understandBtn.frame = CGRectMake(10, NavbarHight+10, SCREEN_WIDTH-20, SCREEN_HEIGHT/3.8);
            [_understandBtn setBackgroundImage:[UIImage imageWithData:data1] forState:UIControlStateNormal];
            _understandBtn.tag =1;
            _understandBtn.layer.masksToBounds = YES; //没这句话它圆不起来
            _understandBtn.layer.cornerRadius = 6.0; //设置图片圆角的尺度
            [_understandBtn addTarget:self action:@selector(got:) forControlEvents:UIControlEventTouchUpInside];
            
            _teacherBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            _teacherBtn.frame = CGRectMake(10, SCREEN_HEIGHT/7.7+SCREEN_HEIGHT/3.8+15, SCREEN_WIDTH-20, SCREEN_HEIGHT/3.8);
            [_teacherBtn setBackgroundImage:[UIImage imageWithData:data2] forState:UIControlStateNormal];
            _teacherBtn.tag =2;
            _teacherBtn.layer.masksToBounds = YES; //没这句话它圆不起来
            _teacherBtn.layer.cornerRadius = 6.0; //设置图片圆角的尺度
            [_teacherBtn addTarget:self action:@selector(gotOne) forControlEvents:UIControlEventTouchUpInside];
            
            
            _makeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            _makeBtn.frame = CGRectMake(10, SCREEN_HEIGHT/7.7+SCREEN_HEIGHT/3.8*2+30, SCREEN_WIDTH/2-15, SCREEN_HEIGHT/7.7);
            [_makeBtn setBackgroundImage:[UIImage imageWithData:data3] forState:UIControlStateNormal];
            _makeBtn.tag =3;
            [_makeBtn addTarget:self action:@selector(gotTow) forControlEvents:UIControlEventTouchUpInside];
            
            
            _makeLabel = [[UILabel alloc]init];
            _makeLabel.frame = CGRectMake(10, SCREEN_HEIGHT/7.7*2+SCREEN_HEIGHT/3.8*2+30, SCREEN_WIDTH/2-15, 30);
            _makeLabel.text = @"早教指导师预约";
            _makeLabel.font = [UIFont systemFontOfSize:11];
            _makeLabel.textAlignment = NSTextAlignmentCenter;
            
            
            _courseBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            _courseBtn.frame = CGRectMake(5+SCREEN_WIDTH/2, SCREEN_HEIGHT/7.7+SCREEN_HEIGHT/3.8*2+30, SCREEN_WIDTH/2-15, SCREEN_HEIGHT/7.7);
            [_courseBtn setBackgroundImage:[UIImage imageWithData:data4] forState:UIControlStateNormal];
            _courseBtn.tag =4;
            [_courseBtn addTarget:self action:@selector(gotSre) forControlEvents:UIControlEventTouchUpInside];
            
            _courseLabel = [[UILabel alloc]init];
            _courseLabel.frame = CGRectMake(5+SCREEN_WIDTH/2, SCREEN_HEIGHT/7.7*2+SCREEN_HEIGHT/3.8*2+30, SCREEN_WIDTH/2-15, 30);
            _courseLabel.text = @"预约课程";
            _courseLabel.font = [UIFont systemFontOfSize:11];
            _courseLabel.textAlignment = NSTextAlignmentCenter;
            

            [self.view addSubview:_understandBtn];
            [self.view addSubview:_teacherBtn];
            [self.view addSubview:_makeBtn];
            [self.view addSubview:_courseBtn];
            [self.view addSubview:_makeLabel];
            [self.view addSubview:_courseLabel];
            
            }else{
                
                [JKAlert showMessage:@"提示" message:@"暂无数据返回"];
                
                
            }
            
        }else
        {
            
            
            
            
        }
    }];
    
  

    
    
    
    
    
    
}


#pragma mark---  了解上门早教的点击方法

-(void)got:(UIButton *)send{
    
    UnderstandViewController * undestandrVC = [[UnderstandViewController alloc]init];
    UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:undestandrVC];
    [self  presentViewController:nav animated:YES completion:nil];
    
    
    
}
#pragma mark---  早教老师介绍
-(void)gotOne{
    
    
    IntroductionViewController * IntroductionVC = [[IntroductionViewController alloc]init];
    UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:IntroductionVC];
    [self  presentViewController:nav animated:YES completion:nil];
    
    
    
}
#pragma mark---  早教指导师预约
-(void)gotTow{
    
    
    AppointmentViewController * AppointmentVC = [[AppointmentViewController alloc]init];
    UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:AppointmentVC];
    [self  presentViewController:nav animated:YES completion:nil];

    
    
    
}
#pragma mark---  预约课程
-(void)gotSre{

    
    CourseViewController * cou = [[CourseViewController alloc]init];
    UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:cou];
    [self presentViewController:nav animated:YES completion:nil];
    
    
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
